home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / public / bit / src / utype.h < prev    next >
C/C++ Source or Header  |  1994-08-01  |  9KB  |  265 lines

  1. /*
  2.  * $Id: utype.h,v 0.91 1994/02/20 00:53:36 zhao Pre-Release $
  3.  *
  4.  *. This file is part of BIT shareware package. After the two weeks of
  5.  *  free evaluation period, you are encouraged (required) to register
  6.  *  your copy for a small registration fee, which is $35 for personal use
  7.  *  and $50 for commercial, government and institutional use.
  8.  *
  9.  *  Copyright(c) 1993, 1994 by T.C. Zhao.
  10.  *  All rights reserved.
  11.  *
  12.  *  Permission to use, copy, and distribute this software in its entirety
  13.  *  for non-commercial purposes is hereby granted, provided that the
  14.  *  above shareware and copyright notices and this permission notice
  15.  *  appear in all copies and their documentation.
  16.  *
  17.  *  This software may be modified for your own use, but modified versions
  18.  *  may not be distributed without prior consent of the author.
  19.  *
  20.  *  This software is provided "as is" without expressed or implied
  21.  *  warranty of any kind.
  22.  *
  23.  *.
  24.  *
  25.  * typedefs, enums and macros. This file should be a basic one, i.e., it
  26.  * should not dependent on any other non-system headers, except errors.
  27.  */
  28.  
  29. #ifndef BIT_UTYPE_H
  30. #define BIT_UTYPE_H
  31.  
  32. #include "ulib.h"
  33.  
  34. #ifndef PROTECT
  35. #ifdef  ADD_TC
  36. #undef  ADD_TC
  37. #endif
  38. #endif
  39.  
  40. /***********************************************************
  41.  * Basic types used
  42.  ***********************************************************/
  43.  
  44. #ifndef type_pc_t
  45. #define type_pc_t
  46.  
  47. /******* raster types ********/
  48.  
  49. typedef unsigned char pc_t;    /* primary color type  */
  50. typedef unsigned short ci_t;    /* colorindex type     */
  51. typedef unsigned long rgba_t;    /* rgba type           */
  52.  
  53. /***** derived types ********/
  54.  
  55. typedef rgba_t gray_t;        /* gray scale type     */
  56. typedef ci_t mapg_t;        /* graymap             */
  57. typedef ci_t bw_t;        /* black & white       */
  58.  
  59. #endif /* !def type_pc_t */
  60.  
  61. /********************************************************************
  62.  * Image types. For format capable of holding more than one type of images
  63.  * assign type T_FLEX to it so that conversion routine will pass the image
  64.  * un-altered to the output routine.
  65.  *
  66.  * all grayscale images can be represented by color maps, and subpixel sampling
  67.  * becomes interpolation of the color indexes. The existence of T_GRAY is a
  68.  * bug.
  69.  *
  70.  * NOTE: after description, type must NOT be T_FLEX.
  71.  
  72.  **********************************************************************/
  73. typedef enum
  74.   {
  75.       T_INVALID = -1,        /* make IMG_TYPE signed type     */
  76.       T_RGBA,            /* packed RGBA values            */
  77.       T_GRAY,            /* packed RGBA grayscale         */
  78.       T_CMAP,            /* mapped images having ci_t type */
  79.       T_GMAP,            /* gray scale mapped images       */
  80.       T_BW,            /* Black & White images          */
  81.       T_RGB,            /* Internal type  (unused)       */
  82.       T_FLEX            /* flexible(unknown) types       */
  83.   } IMG_TYPE;
  84.  
  85. /*
  86.  * macros to check the types. B&W image is currently implemented as a
  87.  * colormapped image with 2 entries in the colormap
  88.  */
  89.  
  90. #define IS_RGBA(i)     (i && i->type == T_RGBA)
  91. #define IS_MGRAY(i)    (i && i->type==T_GMAP)
  92. #define IS_BW(i)       (i && i->type==T_BW)
  93. #define IS_CI(i)       (i && (i->type==T_CMAP || IS_MGRAY(i) || IS_BW(i)))
  94. #define IS_RGBGRAY(i)  (i && i->type==T_GRAY)
  95. #define IS_CPACK(i)    (IS_RGBA(i) || IS_RGBGRAY(i))
  96. #define IS_GRAY(i)     (IS_MGRAY(i) || IS_RGBGRAY(i))
  97.  
  98. /********************************************************************
  99.  * Colormaps: Implemented as straight RGB arrays. Typical hardware will
  100.  * support 12bits (4096), but it is not likely any map-based image
  101.  * will use that many. default to 9 for BIT. Less than 9 might not work.
  102.  ********************************************************************/
  103.  
  104. #include <limits.h>
  105. #ifndef CMAPBITS
  106. #define CMAPBITS 9
  107. #endif
  108.  
  109. /*
  110.  * Note is PCBITS is not 8, i.e., sizeof(pc_t) != 1, PostScript support
  111.  * need to change
  112.  */
  113.  
  114. /* MAXCML-1 MUST be full bits, as it is used as masks sometimes */
  115. #define MAXCML   (1 << CMAPBITS)/* max. length of cmap */
  116. #define PCBITS   (sizeof(pc_t)*CHAR_BIT)    /* primary color bits  */
  117. #define PCMAX    (1 << PCBITS)    /* and its max value + 1   */
  118. #define PCMAXV   (PCMAX-1)    /* max value   */
  119.  
  120. #define BKINDEX  (MAXCML-1)    /* bkgrd index if colormap */
  121.  
  122. /*** normalized color is from 0.0 to 1.0 ***/
  123.  
  124. #define C2NC(c)   ((1.0/PCMAXV) * (c))
  125. #define NC2C(c)   (int)((c) * PCMAXV + 0.4)
  126.  
  127. /* Histograms + peak & ave  & value where peak occured   */
  128.  
  129. typedef unsigned Hist_t[PCMAX + 3];
  130. typedef struct
  131.   {
  132.       int colors;        /* no. of colors in map        */
  133.       int ucolors;        /* no. of uniq. colors         */
  134.       short packed;        /* if packed >0, if histo <0   */
  135.       short sorted;        /* if sorted                   */
  136.       pc_t ct[4][MAXCML];    /* RGB triplets + alpha        */
  137.       union
  138.     {            /* packed  cmap or histogram   */
  139.         rgba_t rgba[MAXCML];/* packed  RGB                 */
  140.         Hist_t hist[4];    /* for RGB & gray histogram    */
  141.     }
  142.       p_h;
  143.   }
  144. C_MAP, *CMPTR;
  145.  
  146. /**************************************************************
  147.  * conversion between rgb and rgba
  148.  **************************************************************/
  149.  
  150. #define Pack3(r,g,b)  ((rgba_t)(r)|((rgba_t)(g)<<8)|((rgba_t)(b)<<16))
  151. #define Pack4(r,g,b,a) (Pack3(r,g,b) |((rgba_t)(a) << 24))
  152.  
  153. #define Unpack(c,r,g,b)                     \
  154.            do {                             \
  155.              r = (  (c)        & PCMAXV);   \
  156.              g = (( (c) >> 8 ) & PCMAXV);   \
  157.              b = (( (c) >> 16) & PCMAXV);   \
  158.            } while (ZERO)
  159.  
  160. #define Pack         Pack3
  161. #define get_R(a)    ( (a)         & PCMAXV)
  162. #define get_G(a)    ( ((a) >> 8)  & PCMAXV)
  163. #define get_B(a)    ( ((a) >> 16) & PCMAXV)
  164.  
  165. #define CPACK2GRAY(c) RGB2GRAY(get_R(c), get_G(c), get_B(c))
  166.  
  167. #define RGB2CPACK Pack
  168. #define CPACK2RGB Unpack
  169.  
  170. /*******************************************************************
  171.  * possible operations on the images. Note that it is not possible to
  172.  * operate on a colormap based image without first converting it to
  173.  * RGB format
  174.  *******************************************************************/
  175.  
  176. typedef enum
  177.   {
  178.       O_INVALID = -1,        /* force type to be signed   */
  179.       O_NONE,            /* null op                   */
  180.       O_SYSOP,            /* Reserved for system use   */
  181.       O_MASK,            /* C= B==0 ? A:B             */
  182.       O_ADD,            /* C = A+B; Min(c, 255)      */
  183.       O_SUB,            /* C = A-B; Max(c, 0)        */
  184.       O_DIFF,            /* Abs(A-B)                  */
  185.       O_XOR            /* A^B                       */
  186.   } Matop_t;
  187.  
  188.  
  189. /**********************************************************
  190.  * help index. does not need to be sorted or in sequence
  191.  **********************************************************/
  192.  
  193. typedef enum
  194.   {
  195.       HELP_CNTL,        /* control panel      */
  196.       HELP_COLEDIT,        /* 1 to 1             */
  197.       HELP_COLOR,        /* color selection    */
  198.       HELP_CONVOLV,        /* extern convolution */
  199.       HELP_CP,            /* cut & paste        */
  200.       HELP_CROP,        /* crop               */
  201.       HELP_EDIT,        /* edit control panel */
  202.       HELP_ERASER,        /* simple cut&paste   */
  203.       HELP_FILTER,        /* external filters   */
  204.       HELP_FSELECT,        /* file selector      */
  205.       HELP_HIST,        /* histogram          */
  206.       HELP_IBBIND,        /* browser binding    */
  207.       HELP_IBR,            /* image browser      */
  208.       HELP_INFO,        /* program info       */
  209.       HELP_JPEG,        /* jpeg help          */
  210.       HELP_LOAD,        /* load/remover       */
  211.       HELP_LSCAN,        /* linear scan        */
  212.       HELP_MARKING,        /* sgfs               */
  213.       HELP_MERGE,        /* merge two images   */
  214.       HELP_MPEG,        /* MPEG               */
  215.       HELP_OPTION,        /* set options        */
  216.       HELP_PAINT,        /* paint help         */
  217.       HELP_PEDIT,        /* pixel edit help    */
  218.       HELP_PS,            /* PostScript help    */
  219.       HELP_QUANT,        /* qunatization       */
  220.       HELP_ROTATE,        /* raster rotate      */
  221.       HELP_SCALE,        /* raster scale       */
  222.       HELP_SMOOTH,        /* smoothing          */
  223.       HELP_TEST,        /* temporary          */
  224.       HELP_TEXT,        /* text               */
  225.       HELP_WRITE,        /* write to disk      */
  226.       HELP_ZOOM            /* magnification      */
  227.   } helpi_t;
  228.  
  229. /*****************************************************************
  230.  * function pointers to binding functions, addto_action etc.
  231.  *****************************************************************/
  232.  
  233. typedef void (*VLfptr) (long);
  234. typedef void (*VVfptr) (void);
  235. typedef void (*VIIpfptr) (int, int *);
  236. typedef void (*Grepaint) (int /* event_redraw */ );
  237. typedef long (*GLQevent) (long /* dev */ , short /* val */ );
  238. typedef long (*GLQhandler) (long /* dev */ , short /* val */ );
  239.  
  240. /****************************************************************
  241.  * Pixel representation independent rectwrite
  242.  ****************************************************************/
  243.  
  244. #define PI_rectwrite(xi, yi, xf, yf, a)                    \
  245.        if(IS_CPACK(imgptr))                            \
  246.          lrectwrite(xi, yi, xf, yf, (rgba_t *)(a));    \
  247.            else                                            \
  248.           rectwrite(xi, yi, xf, yf, (ci_t *)(a))
  249.  
  250. #define PI_rectread(xi, yi, xf, yf, a)                     \
  251.        (IS_CPACK(imgptr) ?                             \
  252.          lrectread(xi, yi, xf, yf, (rgba_t *)(a)):     \
  253.          rectread(xi, yi, xf, yf, (ci_t *)(a)))
  254.  
  255. /**************************************************************
  256.  * rubber bands
  257.  **************************************************************/
  258.  
  259. typedef enum
  260.   {
  261.       RB_RECT, RB_CIRC, RB_LINE, RB_POLY
  262.   } rubber_obj;
  263.  
  264. #endif /* !def RT_UTYPE_H */
  265.